package a09_JUC;

/**
 * @Author quan
 * @Description ThreadLocal的使用
 * @Date 2023/5/22 16:33
 */
public class a09_ThreadLocal {
    //1、初始化一个ThreadLocal
    private static ThreadLocal<Integer> threadLocal = new ThreadLocal<>();
    public static void main(String[] args) {
        Thread thread1 = new Thread(()->{
            //2、统计人数-一班
            int count = 35;
            threadLocal.set(count);
            print();
        });
        Thread thread2 = new Thread(()->{
            //统计人数-二班
            int count = 40;
            threadLocal.set(count);
            print();
        });
        thread1.start();
        thread2.start();
    }
    //3、定制校服
    private static void print() {
        Integer value = threadLocal.get();
        System.out.println(Thread.currentThread().getName()+"需要定制"+value+"套校服");
    }
}
